"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = main;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const readline = __importStar(require("readline"));
// 枚举定义
var FieldType;
(function (FieldType) {
    FieldType["PARAM"] = "param";
    FieldType["RETURN"] = "return";
    FieldType["FIELD"] = "field";
    FieldType["CLASS"] = "class";
    FieldType["OPERATOR"] = "operator";
    FieldType["OVERLOAD"] = "overload";
    FieldType["TYPE"] = "type";
    FieldType["ENUM"] = "enum";
})(FieldType || (FieldType = {}));
// 类型信息类
class TypeInfo {
    constructor(name, description = "", lineNumber = 0) {
        this.name = name;
        this.description = description;
        this.lineNumber = lineNumber;
    }
}
// 字段信息类
class FieldInfo {
    constructor(name, typeInfo, description = "", fieldType = FieldType.FIELD, value = null, deprecated = null, // 新增：废弃信息
    see = [] // 新增：参考信息
    ) {
        this.name = name;
        this.typeInfo = typeInfo;
        this.description = description;
        this.fieldType = fieldType;
        this.value = value;
        this.deprecated = deprecated;
        this.see = see;
    }
}
// 枚举值信息类
class EnumValueInfo {
    constructor(name, value, description = "", lineNumber = 0, deprecated = null, // 新增：废弃信息
    see = [] // 新增：参考信息
    ) {
        this.name = name;
        this.value = value;
        this.description = description;
        this.lineNumber = lineNumber;
        this.deprecated = deprecated;
        this.see = see;
    }
}
// 函数信息类
class FunctionInfo {
    constructor(name, params = [], returns = [], description = "", lineNumber = 0, isStatic = false, deprecated = null, // 新增：废弃信息
    see = [] // 新增：参考信息
    ) {
        this.name = name;
        this.params = params;
        this.returns = returns;
        this.description = description;
        this.lineNumber = lineNumber;
        this.isStatic = isStatic;
        this.deprecated = deprecated;
        this.see = see;
    }
}
// 类信息类
class ClassInfo {
    constructor(name, fields = [], methods = [], staticMethods = [], typeDefs = [], parents = [], description = "", lineNumber = 0, isModule = false, deprecated = null, // 新增：废弃信息
    see = [] // 新增：参考信息
    ) {
        this.name = name;
        this.fields = fields;
        this.methods = methods;
        this.staticMethods = staticMethods;
        this.typeDefs = typeDefs;
        this.parents = parents;
        this.description = description;
        this.lineNumber = lineNumber;
        this.isModule = isModule;
        this.deprecated = deprecated;
        this.see = see;
    }
}
// 枚举信息类
class EnumInfo {
    constructor(name, values = [], description = "", lineNumber = 0, deprecated = null, // 新增：废弃信息
    see = [] // 新增：参考信息
    ) {
        this.name = name;
        this.values = values;
        this.description = description;
        this.lineNumber = lineNumber;
        this.deprecated = deprecated;
        this.see = see;
    }
}
// 类型解析器
class TypeParser {
    constructor() {
        this.typeHandlers = {};
        this.registerBuiltinHandlers();
    }
    registerBuiltinHandlers() {
        this.registerType("Fixed", this.parseFixedType.bind(this));
        this.registerType("Vector3", this.parseVector3Type.bind(this));
        this.registerType("Quaternion", this.parseQuaternionType.bind(this));
        this.registerType("dict", this.parseDictType.bind(this));
    }
    registerType(typeName, handler) {
        this.typeHandlers[typeName] = handler;
    }
    parseType(typeStr, lineNumber = 0) {
        typeStr = typeStr.trim();
        for (const [typeName, handler] of Object.entries(this.typeHandlers)) {
            if (typeStr.startsWith(typeName)) {
                return handler(typeStr, lineNumber);
            }
        }
        return new TypeInfo(typeStr, "", lineNumber);
    }
    parseFixedType(typeStr, lineNumber) {
        return new TypeInfo("Fixed", "定点数类型", lineNumber);
    }
    parseVector3Type(typeStr, lineNumber) {
        return new TypeInfo("Vector3", "三维向量", lineNumber);
    }
    parseQuaternionType(typeStr, lineNumber) {
        return new TypeInfo("Quaternion", "四元数", lineNumber);
    }
    parseDictType(typeStr, lineNumber) {
        return new TypeInfo("dict", "字典类型", lineNumber);
    }
}
// Lua API解析器
class LuaAPIParser {
    constructor() {
        this.currentClass = null;
        this.currentEnum = null;
        this.classes = {};
        this.enums = {};
        this.functions = [];
        this.currentDescription = [];
        this.currentDeprecated = null; // 新增：当前废弃信息
        this.currentSee = []; // 新增：当前参考信息
        this.typeParser = new TypeParser();
        this.patterns = {
            'class': /---@class\s+(\w+)(?:\s*:\s*([\w\s,]+))?/,
            'field': /---@field\s+(\w+)\s+(\S+)(?:\s+(.*))?/,
            'type': /---@type\s+(\S+)(?:\s+(.*))?/,
            'enum': /---@enum\s+([\w\.]+)(?:\s+(.*))?/,
            'param': /---@param\s+(\w+)\s+(\S+)(?:\s+(.*))?/,
            'return': /---@return\s+(\S+)(?:\s+(.*))?/,
            'overload': /---@overload\s+fun\(([^)]*)\):\s*(.+)/,
            'operator': /---@operator\s+(\S+)\s*\(([^)]+)\):\s*(\S+)/,
            'function': /function\s+([\w:\.]+)\s*\(([^)]*)\)/,
            'static_method': /function\s+(\w+)\.(\w+)\s*\(([^)]*)\)/,
            'method': /function\s+(\w+):(\w+)\s*\(([^)]*)\)/,
            'assignment': /(\w+(?:\.\w+)*)\s*=\s*([^=]+)$/,
            'module_decl': /^(\w+)$/,
            'enum_value': /(\w+)\s*=\s*([^,]+),?\s*(?:---\s*(.*))?/,
            'description': /^---(.*)/,
            'deprecated': /---@deprecated(?:\s+(.*))?/, // 新增：废弃注释
            'see': /---@see\s+(.+)/ // 新增：参考注释
        };
    }
    registerCustomType(typeName, handler) {
        this.typeParser.registerType(typeName, handler);
    }
    async parseFile(filePath) {
        const fileStream = fs.createReadStream(filePath);
        const rl = readline.createInterface({
            input: fileStream,
            crlfDelay: Infinity
        });
        const lines = [];
        for await (const line of rl) {
            lines.push(line);
        }
        this.parseLines(lines);
    }
    parseText(text) {
        const lines = text.split('\n');
        this.parseLines(lines);
    }
    parseLines(lines) {
        let currentFunction = null;
        let currentParams = [];
        let currentReturns = [];
        let pendingTypeDef = null;
        let parsingEnum = false;
        let currentEnumName = null; // 新增：当前枚举名
        lines.forEach((line, index) => {
            const lineNumber = index + 1;
            const trimmedLine = line.trim();
            // +++ 新增：处理操作符注释 +++
            const operatorMatch = trimmedLine.match(this.patterns['operator']);
            if (operatorMatch) {
                this.handleOperatorDefinition(operatorMatch, lineNumber);
                return;
            }
            // 处理废弃注释
            const deprecatedMatch = trimmedLine.match(this.patterns['deprecated']);
            if (deprecatedMatch) {
                this.currentDeprecated = deprecatedMatch[1]?.trim() || "Deprecated";
                return;
            }
            // 处理参考注释
            const seeMatch = trimmedLine.match(this.patterns['see']);
            if (seeMatch) {
                this.currentSee.push(seeMatch[1].trim());
                return;
            }
            // 处理枚举定义
            const enumMatch = trimmedLine.match(this.patterns['enum']);
            if (enumMatch) {
                console.log(`Found enum definition at line ${lineNumber}:`, enumMatch[0]);
                this.handleEnumDefinition(enumMatch, lineNumber);
                parsingEnum = true;
                currentEnumName = enumMatch[1]; // 保存当前枚举名
                return;
            }
            // +++ 修改：处理枚举赋值行 +++
            if (parsingEnum && currentEnumName && trimmedLine.startsWith(currentEnumName)) {
                console.log(`Found enum assignment at line ${lineNumber}: ${trimmedLine}`);
                // 检查是否是枚举结束
                if (trimmedLine.includes('}')) {
                    console.log(`End of enum at line ${lineNumber}`);
                    parsingEnum = false;
                    currentEnumName = null;
                    return;
                }
                // 跳过赋值行，不处理
                return;
            }
            // +++ 修改：处理枚举值 +++
            if (parsingEnum && currentEnumName && this.enums[currentEnumName]) {
                // 检查是否是枚举结束
                if (trimmedLine === '}') {
                    console.log(`End of enum at line ${lineNumber}`);
                    parsingEnum = false;
                    currentEnumName = null;
                    return;
                }
                // 处理枚举值
                const enumValueMatch = trimmedLine.match(this.patterns['enum_value']);
                if (enumValueMatch) {
                    console.log(`Found enum value at line ${lineNumber}:`, enumValueMatch[0]);
                    this.handleEnumValue(enumValueMatch, lineNumber, currentEnumName);
                    return;
                }
                else {
                    console.log(`No enum value match for line ${lineNumber}: "${trimmedLine}"`);
                }
            }
            // 处理类定义
            const classMatch = trimmedLine.match(this.patterns['class']);
            if (classMatch) {
                this.handleClassDefinition(classMatch, lineNumber);
                return;
            }
            // 处理类型定义
            const typeMatch = trimmedLine.match(this.patterns['type']);
            if (typeMatch) {
                pendingTypeDef = this.handleTypeDefinition(typeMatch, lineNumber);
                return;
            }
            // 处理赋值语句
            const assignmentMatch = trimmedLine.match(this.patterns['assignment']);
            if (assignmentMatch && pendingTypeDef) {
                this.handleAssignmentWithType(assignmentMatch, pendingTypeDef, lineNumber);
                pendingTypeDef = null;
                return;
            }
            else if (assignmentMatch && this.currentClass) {
                this.handleModuleAssignment(assignmentMatch, lineNumber);
                return;
            }
            // 处理描述信息
            const descMatch = trimmedLine.match(this.patterns['description']);
            if (descMatch && !this.isAnnotationLine(trimmedLine)) {
                const desc = descMatch[1].trim();
                if (desc)
                    this.currentDescription.push(desc);
                return;
            }
            // 处理模块声明
            const moduleMatch = trimmedLine.match(this.patterns['module_decl']);
            if (moduleMatch && this.currentClass &&
                !trimmedLine.startsWith('---') &&
                !trimmedLine.startsWith('function')) {
                const className = moduleMatch[1];
                if (className === this.currentClass.name) {
                    this.currentClass.isModule = true;
                }
                return;
            }
            // 处理字段定义
            const fieldMatch = trimmedLine.match(this.patterns['field']);
            if (fieldMatch && this.currentClass) {
                this.handleFieldDefinition(fieldMatch, lineNumber);
                return;
            }
            // 处理参数定义
            const paramMatch = trimmedLine.match(this.patterns['param']);
            if (paramMatch) {
                currentParams.push(this.createFieldInfo(paramMatch, FieldType.PARAM, lineNumber));
                return;
            }
            // 处理返回值定义
            const returnMatch = trimmedLine.match(this.patterns['return']);
            if (returnMatch) {
                currentReturns.push(this.createFieldInfo(returnMatch, FieldType.RETURN, lineNumber));
                return;
            }
            // 处理静态方法定义
            const staticMethodMatch = trimmedLine.match(this.patterns['static_method']);
            if (staticMethodMatch) {
                if (currentFunction)
                    this.saveFunction(currentFunction, currentParams, currentReturns);
                currentFunction = this.parseStaticMethodDefinition(staticMethodMatch, lineNumber);
                currentParams = [];
                currentReturns = [];
                return;
            }
            // 处理方法定义
            const methodMatch = trimmedLine.match(this.patterns['method']);
            if (methodMatch) {
                if (currentFunction)
                    this.saveFunction(currentFunction, currentParams, currentReturns);
                currentFunction = this.parseMethodDefinition(methodMatch, lineNumber);
                currentParams = [];
                currentReturns = [];
                return;
            }
            // 处理普通函数定义
            const funcMatch = trimmedLine.match(this.patterns['function']);
            if (funcMatch) {
                if (currentFunction)
                    this.saveFunction(currentFunction, currentParams, currentReturns);
                currentFunction = this.parseFunctionDefinition(funcMatch, lineNumber);
                currentParams = [];
                currentReturns = [];
                return;
            }
        });
        // 处理最后一个函数
        if (currentFunction) {
            this.saveFunction(currentFunction, currentParams, currentReturns);
        }
    }
    isAnnotationLine(line) {
        return [
            this.patterns['class'],
            this.patterns['field'],
            this.patterns['type'],
            this.patterns['enum'],
            this.patterns['param'],
            this.patterns['return'],
            this.patterns['deprecated'], // 新增
            this.patterns['see'] // 新增
        ].some(pattern => pattern.test(line));
    }
    // +++ 新增：处理操作符定义 +++
    handleOperatorDefinition(match, lineNumber) {
        const operatorName = match[1];
        const paramsStr = match[2];
        const returnType = match[3];
        // 解析参数
        const params = paramsStr.split(',').map(param => {
            const paramParts = param.trim().split(':');
            const paramName = paramParts[0].trim();
            const paramType = paramParts[1]?.trim() || "any";
            return new FieldInfo(paramName, this.typeParser.parseType(paramType, lineNumber), "", FieldType.PARAM);
        });
        // 解析返回值
        const returns = [new FieldInfo("", this.typeParser.parseType(returnType, lineNumber), "", FieldType.RETURN)];
        // 创建函数名（使用operator_前缀避免冲突）
        const functionName = `operator_${operatorName}`;
        // 创建函数信息
        const functionInfo = new FunctionInfo(functionName, params, returns, this.currentDescription.join(' ') || "", lineNumber, false, this.currentDeprecated, [...this.currentSee]);
        // 添加到函数列表
        this.functions.push(functionInfo);
        // 重置状态
        this.currentDescription = [];
        this.currentDeprecated = null;
        this.currentSee = [];
    }
    handleEnumDefinition(match, lineNumber) {
        const enumName = match[1];
        const description = match[2]?.trim() || this.currentDescription.join(' ') || "";
        console.log(`Creating enum: ${enumName} with description: ${description}`);
        this.enums[enumName] = new EnumInfo(enumName, // 使用完整枚举名
        [], description, lineNumber, this.currentDeprecated, [...this.currentSee]);
        // 重置状态
        this.currentDescription = [];
        this.currentDeprecated = null;
        this.currentSee = [];
    }
    handleEnumValue(match, lineNumber, enumName) {
        if (!this.enums[enumName]) {
            console.log(`Enum ${enumName} not found at line ${lineNumber}`);
            return;
        }
        const name = match[1];
        let value = match[2].trim();
        const description = match[3]?.trim() || "";
        console.log(`Processing enum value: ${name} = ${value}`);
        // 处理值（可能是数字、字符串等）
        try {
            // 尝试解析为整数
            if (/^-?\d+$/.test(value)) {
                value = parseInt(value);
            }
            // 尝试解析为浮点数
            else if (/^-?\d+\.\d+$/.test(value)) {
                value = parseFloat(value);
            }
            // 处理字符串值（带引号）
            else if ((value.startsWith('"') && value.endsWith('"')) ||
                (value.startsWith("'") && value.endsWith("'"))) {
                value = value.substring(1, value.length - 1);
            }
            // 处理布尔值
            else if (value === 'true' || value === 'false') {
                value = value === 'true';
            }
        }
        catch (error) {
            console.log(`Error parsing enum value: ${error}`);
        }
        const enumValue = new EnumValueInfo(name, value, description, lineNumber, this.currentDeprecated, [...this.currentSee]);
        this.enums[enumName].values.push(enumValue);
        console.log(`Added enum value: ${name} = ${value} to enum ${enumName}`);
        // 重置状态
        this.currentDescription = [];
        this.currentDeprecated = null;
        this.currentSee = [];
    }
    handleClassDefinition(match, lineNumber) {
        const className = match[1];
        const inheritanceStr = match[2];
        const parents = inheritanceStr ? inheritanceStr.split(',').map(p => p.trim()) : [];
        const description = this.currentDescription.join(' ') || "";
        this.currentClass = new ClassInfo(className, [], [], [], [], parents, description, lineNumber, false, this.currentDeprecated, // 新增：废弃信息
        [...this.currentSee] // 新增：参考信息
        );
        this.classes[className] = this.currentClass;
        // 重置状态
        this.currentDescription = [];
        this.currentDeprecated = null;
        this.currentSee = [];
    }
    handleTypeDefinition(match, lineNumber) {
        const typeStr = match[1];
        const description = match[2]?.trim() || this.currentDescription.join(' ') || "";
        const typeInfo = this.typeParser.parseType(typeStr, lineNumber);
        return {
            typeInfo,
            description,
            lineNumber,
            deprecated: this.currentDeprecated, // 新增：废弃信息
            see: [...this.currentSee] // 新增：参考信息
        };
    }
    handleAssignmentWithType(match, typeDef, lineNumber) {
        const varName = match[1];
        const value = match[2];
        let fieldName = varName;
        if (this.currentClass && varName.includes('.')) {
            const parts = varName.split('.');
            if (parts[0] === this.currentClass.name) {
                fieldName = parts[1];
            }
        }
        const fieldInfo = new FieldInfo(fieldName, typeDef.typeInfo, typeDef.description, FieldType.TYPE, value, typeDef.deprecated, // 新增：废弃信息
        typeDef.see // 新增：参考信息
        );
        if (this.currentClass) {
            this.currentClass.typeDefs.push(fieldInfo);
        }
        // 重置状态
        this.currentDescription = [];
        this.currentDeprecated = null;
        this.currentSee = [];
    }
    handleModuleAssignment(match, lineNumber) {
        const varName = match[1];
        const value = match[2];
        if (this.currentClass && varName.includes('.')) {
            const parts = varName.split('.');
            if (parts[0] === this.currentClass.name) {
                const fieldName = parts[1];
                const description = this.currentDescription.join(' ') || "";
                this.currentClass.fields.push(new FieldInfo(fieldName, new TypeInfo("string"), description, FieldType.FIELD, value, this.currentDeprecated, // 新增：废弃信息
                [...this.currentSee] // 新增：参考信息
                ));
                // 重置状态
                this.currentDescription = [];
                this.currentDeprecated = null;
                this.currentSee = [];
                return;
            }
        }
        if (varName === this.currentClass?.name) {
            this.currentClass.isModule = true;
        }
    }
    handleFieldDefinition(match, lineNumber) {
        if (!this.currentClass)
            return;
        const fieldName = match[1];
        const typeStr = match[2];
        const description = match[3]?.trim() || this.currentDescription.join(' ') || "";
        const typeInfo = this.typeParser.parseType(typeStr, lineNumber);
        this.currentClass.fields.push(new FieldInfo(fieldName, typeInfo, description, FieldType.FIELD, null, this.currentDeprecated, // 新增：废弃信息
        [...this.currentSee] // 新增：参考信息
        ));
        // 重置状态
        this.currentDescription = [];
        this.currentDeprecated = null;
        this.currentSee = [];
    }
    createFieldInfo(match, fieldType, lineNumber) {
        let name = "";
        let typeStr = "";
        let description = "";
        if (fieldType === FieldType.PARAM) {
            name = match[1];
            typeStr = match[2];
            description = match[3]?.trim() || "";
        }
        else { // RETURN
            typeStr = match[1];
            description = match[2]?.trim() || "";
        }
        const typeInfo = this.typeParser.parseType(typeStr, lineNumber);
        return new FieldInfo(name, typeInfo, description, fieldType, null, this.currentDeprecated, // 新增：废弃信息
        [...this.currentSee] // 新增：参考信息
        );
    }
    parseStaticMethodDefinition(match, lineNumber) {
        return {
            name: `${match[1]}.${match[2]}`,
            className: match[1],
            methodName: match[2],
            paramsStr: match[3],
            lineNumber,
            isStatic: true,
            deprecated: this.currentDeprecated, // 新增：废弃信息
            see: [...this.currentSee] // 新增：参考信息
        };
    }
    parseMethodDefinition(match, lineNumber) {
        return {
            name: `${match[1]}:${match[2]}`,
            className: match[1],
            methodName: match[2],
            paramsStr: match[3],
            lineNumber,
            isStatic: false,
            deprecated: this.currentDeprecated, // 新增：废弃信息
            see: [...this.currentSee] // 新增：参考信息
        };
    }
    parseFunctionDefinition(match, lineNumber) {
        return {
            name: match[1],
            paramsStr: match[2],
            lineNumber,
            isStatic: false,
            deprecated: this.currentDeprecated, // 新增：废弃信息
            see: [...this.currentSee] // 新增：参考信息
        };
    }
    saveFunction(funcInfo, params, returns) {
        const description = this.currentDescription.join(' ') || "";
        const functionInfo = new FunctionInfo(funcInfo.name, params, returns, description, funcInfo.lineNumber, funcInfo.isStatic, funcInfo.deprecated, // 新增：废弃信息
        funcInfo.see // 新增：参考信息
        );
        if (funcInfo.className && this.classes[funcInfo.className]) {
            if (funcInfo.isStatic) {
                this.classes[funcInfo.className].staticMethods.push(functionInfo);
            }
            else {
                this.classes[funcInfo.className].methods.push(functionInfo);
            }
        }
        else {
            this.functions.push(functionInfo);
        }
        // 重置状态
        this.currentDescription = [];
        this.currentDeprecated = null;
        this.currentSee = [];
    }
    getClasses() {
        return this.classes;
    }
    getEnums() {
        return this.enums;
    }
    getFunctions() {
        return this.functions;
    }
    getInheritanceTree(className, visited = new Set()) {
        if (!this.classes[className] || visited.has(className))
            return [];
        visited.add(className);
        const inheritanceTree = [className];
        for (const parent of this.classes[className].parents) {
            inheritanceTree.push(...this.getInheritanceTree(parent, visited));
        }
        return inheritanceTree;
    }
    fixKeyOffset(classMethods) {
        const keys = Object.keys(classMethods);
        if (keys.length < 2)
            return classMethods; // 少于2个函数无需处理
        const fixedClassMethods = {};
        // 第一个键保持不变
        fixedClassMethods[keys[0]] = classMethods[keys[0]];
        // 从第二个键开始，将键名向前偏移一位
        for (let i = 1; i < keys.length; i++) {
            fixedClassMethods[keys[i]] = classMethods[keys[i - 1]];
        }
        return fixedClassMethods;
    }
} // 修改主函数中的枚举处理部分
async function main() {
    const parser = new LuaAPIParser();
    try {
        const filePath = path.join(__dirname, 'EggyAPI.lua');
        await parser.parseFile(filePath);
        const classMethods = {};
        const events = {};
        const enums = {};
        // 处理类方法
        for (const [className, classInfo] of Object.entries(parser.getClasses())) {
            if (className === 'EVENT' || className === 'Enums')
                continue;
            for (const method of [...classInfo.methods, ...classInfo.staticMethods]) {
                const { name, ...methodInfo } = method;
                classMethods[name] = methodInfo;
            }
        }
        // 处理事件
        const eventClass = parser.getClasses()['EVENT'];
        if (eventClass) {
            for (const field of eventClass.fields) {
                const eventName = `${eventClass.name}.${field.name}`;
                const { name, typeInfo, fieldType, ...fieldInfo } = field;
                events[eventName] = fieldInfo;
            }
        }
        // 处理枚举
        for (const [enumName, enumInfo] of Object.entries(parser.getEnums())) {
            console.log(`Processing enum: ${enumName} with ${enumInfo.values.length} values`); // 调试信息
            for (const enumValue of enumInfo.values) {
                const fullName = `${enumName}.${enumValue.name}`;
                const { name, ...valueInfo } = enumValue;
                enums[fullName] = valueInfo;
                console.log(`Added enum value: ${fullName} = ${valueInfo.value}`); // 调试信息
            }
        }
        // 处理函数
        const functions = parser.getFunctions().map(fn => {
            const { name, ...fnInfo } = fn;
            return fnInfo;
        });
        // 生成JSON结果
        const jsonLuaAPI = {
            classMethods: parser.fixKeyOffset(classMethods), // 添加键名偏移处理
            enums,
            events,
            functions
        };
        // 写入文件
        const outputPath = path.join(__dirname, 'LUAapi_result.json');
        fs.writeFileSync(outputPath, JSON.stringify(jsonLuaAPI, null, 2), 'utf-8');
        console.log('解析完成，结果已保存到 LUAapi_result.json');
        // +++ 输出调试信息 +++
        console.log('\n=== 调试信息 ===');
        console.log(`解析的枚举数量: ${Object.keys(parser.getEnums()).length}`);
        for (const [enumName, enumInfo] of Object.entries(parser.getEnums())) {
            console.log(`枚举 ${enumName}: ${enumInfo.values.length} 个值`);
            for (const value of enumInfo.values) {
                console.log(`  ${value.name} = ${value.value}`);
            }
        }
    }
    catch (error) {
        console.error('解析过程中出错:', error);
    }
}
